package com.example.myapplication.fragment;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.data.NewListData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

public class PageActivity extends AppCompatActivity {
    private ImageView imags;
    private TextView text;
    private ImageView exit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page);
        Intent intent = getIntent();
        String str = intent.getStringExtra(Common.COMMON);
        init();
        exit_();
        getPage(str);
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PageActivity.this.finish();
            }
        });
    }

    private void getPage(String id) {
        String url = "prod-api/api/park/press/press/list?id="+id+"&pageSize=1&pageNum=1";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, NewListData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                NewListData newListData = (NewListData) obj;

               runOnUiThread(new Runnable() {
                   @Override
                   public void run() {
                       PageAdapter(newListData);
                   }
               });
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void PageAdapter(NewListData newListData) {
        Glide.with(PageActivity.this).load(OkHttpTool.URL+newListData.getRows().get(0).getCover()).into(imags);
        String content = newListData.getRows().get(0).getContent();
        String str = Html.fromHtml(content).toString();
        text.setText(str);
    }

    private void init() {
        imags = findViewById(R.id.imags);
        text = findViewById(R.id.text);
        exit = findViewById(R.id.exit);

    }
}